<template>
  <el-row class="addOrEdit">
    <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="100px">
      <el-form-item label="手机号码" prop="telephone">
        <el-col :span="6">
          <el-input v-model="ruleForm.telephone" placeholder="请输入手机号码"></el-input>
        </el-col>
      </el-form-item>
      <el-form-item label="职位">
        <el-select v-model="ruleForm.dutyNum" placeholder="请选择职位">
          <el-option label="主任" value="1"></el-option>
          <el-option label="副主任" value="2"></el-option>
          <el-option label="委员" value="3"></el-option>
        </el-select>
      </el-form-item>
       <el-form-item>
        <el-button type="primary" size="small" @click="submitForm('ruleForm')">添加</el-button>
        <el-button size="small" @click="rePrev">返回</el-button>
      </el-form-item>
    </el-form>
  </el-row>
</template>

<script>
  export default{
    data(){
      return {
        rules: {
          telephone: [
            { required: true, message: '请输入手机号码', trigger: 'blur' }
          ],
          dutyNum: [
            {type:'number',required: true, message: '请选择职位', trigger: 'change' }
          ]
        }
      }
    },
    props:{
      dtype:{
        type:String,
        default:"add"
      },
      ruleForm:{
        type:Object,
        default(){
          return{
            communityId: "",
            name: "",
            telephone: "",
            time: "",
            house: "",
            dutyNum:"",
            group:"",
            buildNum:"",          //楼栋
            unitNum:""               //单元
          }
        }
      }
    },
    methods: {
      submitForm(formName) {
        this.$refs[formName].validate((valid) => {
          if (valid) {
            let url = "/committee/"+(this.dtype=="add"?"addMember":"modifyMember");
            let p = {
              communityId:this.ruleForm.communityId,		//小区id
              phoneNum:this.ruleForm.telephone,		//业主电话
              memberType:this.ruleForm.dutyNum*1		//类型(1:主任,2:副主任,3:委员)
            };
            this.$http
              .fetch(url, p)
              .then(res => {
                this.$emit("rePrev",true);
            })
            .catch(err => {});
          } else {
              return false;
          }
        });
      },
      rePrev() {
        this.$emit("rePrev");
      }
    }
  }
</script>

<style>
</style>
